// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-10 10:13
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DynamicPlan;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;

public class GetMaximumGenerated {
    /**
     * 获取不确定动规划数组的第n个值
     */
    public int getMaximumGenerated(int n) {
        // 生成指定长度的动态数组 -> 获取指定位置数组
        // 偶数索引的元素大小是自己，奇数位置的元素是其一半 + 一半 +1
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        int max = 0;
        int[] ans = new int[n + 1];
        ans[0] = 0;
        ans[1] = 1;
        for (int i = 2; i <= n; i++) {
            if (i % 2 == 0) {
                ans[i] = ans[i / 2];
            } else {
                ans[i] = ans[i / 2] + ans[(i / 2) + 1];
            }
            if (max < ans[i]) {
                max = ans[i];
            }
        }
        System.out.println(Arrays.stream(ans).boxed().collect(toList()));

        return max;
    }


}
